#include "mainlayoutview.h"
#include "ui_mainlayoutview.h"
#include "maincontroller.h"
#include "sqlcontroller.h"
#include "config.h"
#include <QDebug>
#include <QString>
#include <QCryptographicHash>
#include <QSqlQuery>

MainLayoutView::MainLayoutView(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainLayoutView)
{
    ui->setupUi(this);
    this->setWindowTitle(tr("登录界面"));

    MainController::getInstance()->initMainLayoutView(this);
    if(SqlController::getInstance()->initDataBase())
    {
        return;
    }

}

MainLayoutView::~MainLayoutView()
{
    delete ui;

}


void MainLayoutView::on_btn_login_clicked()
{
    QString strUsername = ui->editusername->text();
    QString strPassword = ui->editpassword->text();

    if(SqlController::getInstance()->goMainLayout(strUsername, strPassword))
    {
        qDebug() << "mainlayout success";
        // 登录成功跳转到主界面
        MainController::getInstance()->hideMainLayoutView();
        MainController::getInstance()->showMainView();
    }
    else
    {
        qDebug() << "mainlayout failed";
    }



}


void MainLayoutView::on_btn_quit_clicked()
{
  exit(0);
}


void MainLayoutView::on_btn_register_clicked()
{
    QString strUsername = ui->editusername->text();
    QString strPassword = ui->editpassword->text();

    if(SqlController::getInstance()->goRegister(strUsername, strPassword))
    {
        qDebug() << "reg success";
    }
    else
    {
        qDebug() << "reg failed";
    }


}


